﻿using System;
using System.Collections.Generic;
using System.Text;
using Framework.Message.SMS.CommonLibrary;
using Framework.Message.SMS.CommonLibrary.Generic;

namespace Framework.Message.SMS.SGIP
{
    public abstract class Command : BaseCommand<SGIPCommandType, CommandSequence, CommandHeader>
    {
        public Command()
            : base()
        {

        }

        public Command(byte[] bytes)
            : base(bytes)
        {
        }

        public Command(byte[] bytes, int startIndex)
            : base(bytes, startIndex)
        {
        }

        public Command(CommandSequence sequence)
            : base(sequence)
        {
        }

        public override bool CheckCommandType(byte[] bytes, int startIndex)
        {
            if (bytes.Length > CommandHeader.HeaderLength)
            {
                return (SGIPCommandType)ByteIntConvert.Bytes2UInt(bytes, startIndex + 4) == this.CommandType;
            }
            else
            {
                return false;
            }
        }

        protected override CommandHeader CreateHeader(SGIPCommandType commandType, CommandSequence sequence)
        {
            return new CommandHeader(commandType, bodyLength, sequence);
        }

        protected override CommandHeader CreateHeader(byte[] bytes, int startIndex)
        {
            return new CommandHeader(bytes, startIndex);
        }
    }
}
